<?php

class Empeval_Methods_Data_BaseBonusGoalsForm {
	
	const DISABLE_FORM_STATUS = 100;
	
	public $id;
	public $year;
	public $type;
	public $status;
	public $comment;
	public $noAcceptReason;
	public $lastModified;
	public $created;
	/**
	 *
	 * @var Empeval_Methods_Data_BonusPeriod
	 */
	public $bonusPeriod = null;
	/**
	 *
	 * @var Empeval_Methods_Data_BaseUser
	 */
	public $editor = null;
	/**
	 *
	 * @var Empeval_Methods_Data_BaseUser
	 */
	public $user = null;
	/**
	 * 
	 * @var Empeval_Methods_Data_Unit
	 */
	public $unit = null;
	/**
	 * 
	 * @var Empeval_Methods_Data_Position
	 */
	public $position = null;
	
	public function __construct($bgf) {
		if ($bgf != null) {
			$userPosition = ($bgf instanceof EmpevalViewBgfWithSuperiorPositionId) ? $bgf->getUserPositionsRelatedByUserPositionId() : $bgf-> getUserPositions();
			$this->id = $bgf->getId();
			$this->year = $bgf->getYear();
			$this->type = $bgf->getType();
			$this->status = $bgf->getStatus();
			$this->comment = $bgf->getComment();
			$this->unit = new Empeval_Methods_Data_Unit($userPosition->getUnits());
			$this->position = new Empeval_Methods_Data_Position($userPosition->getPositions());
			$this->noAcceptReason = $bgf->getNoAcceptReason();
			$this->lastModified = $bgf->getLastModified();
			$this->created = $bgf->getCreated();
			if ($bgf->getBonusPeriods() instanceof EmpevalBonusPeriods) {
				$this->bonusPeriod = new Empeval_Methods_Data_BonusPeriod($bgf->getBonusPeriods(), $userPosition, $bgf->getYear());
			}
			if ($bgf->getUsers() instanceof EmpevalUsers) {
				$this->editor = new Empeval_Methods_Data_BaseUser($bgf->getUsers());
				if ($this->editor->id != Empeval_Auth::getInstance()->getUser()->getId())
					$this->status = self::DISABLE_FORM_STATUS;
			}
		}
	}
	
	public function setUserData(EmpevalUsers $user) {
		$this->user = new Empeval_Methods_Data_BaseUser($user, true);
	}
	
}